import 'package:equatable/equatable.dart';
import 'package:backend.purchases/domain/entities/app_store_api/app_store_api_transaction_ownership_type.dart';

class AppStoreApiTransactionOwnershipTypeDto extends Equatable {
  const AppStoreApiTransactionOwnershipTypeDto._internal({
    required this.ownershipTypeString,
  });

  final String ownershipTypeString;

  @override
  List<Object?> get props {
    return [
      ownershipTypeString,
    ];
  }

  factory AppStoreApiTransactionOwnershipTypeDto.fromString(String ownershipTypeString) {
    return AppStoreApiTransactionOwnershipTypeDto._internal(
      ownershipTypeString: ownershipTypeString,
    );
  }

  AppStoreApiTransactionOwnershipType toEntity() {
    if (ownershipTypeString == 'PURCHASED') {
      return AppStoreApiTransactionOwnershipType.purchase;
    }

    if (ownershipTypeString == 'FAMILY_SHARED') {
      return AppStoreApiTransactionOwnershipType.familySharing;
    }

    throw UnimplementedError();
  }
}
